package com.hmdp.listener;

import com.hmdp.entity.VoucherOrder;
import com.hmdp.service.IVoucherOrderService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class VoucherOrderListener {

    @Autowired
    private IVoucherOrderService voucherOrderService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "order.success.queue", durable = "true"),
            exchange = @Exchange(name = "order.direct"),
            key = "order.success"
    ))
    public void listenCreateOrder(VoucherOrder voucherOrder){
        voucherOrderService.createVoucherOrder(voucherOrder);
    }
}
